package com.xintonghua.bussiness.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.xintonghua.bussiness.R;


/**
 * 订单取消的时候弹出的dialog
 */
public class CommonDialog extends Dialog implements View.OnClickListener {
    private TextView tvTitle;
    private TextView btnCancel;
    private TextView btnSure;
    private Context context;
    private int order=-1;
    private String url;
    private DialogClickListener dialogClickListener;

    public CommonDialog(Context context) {
        super(context, R.style.dialog);
        this.context = context;
        initData();
        initView();
        initListener();
    }

    private void initData() {

    }

    private void initView() {
        setContentView(R.layout.dialog_common);
        tvTitle = (TextView) findViewById(R.id.edit_write);
        btnCancel = (TextView) findViewById(R.id.text_cancel);
        btnSure = (TextView) findViewById(R.id.text_sure);
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setOrder(int order){
        this.order=order;
    }

    public void setAlert(String alert) {
        tvTitle.setText(alert);
    }

    public void setSureButton(String sure) {
        btnSure.setText(sure);
    }

    public void setCancelButton(String cancel) {
        btnCancel.setText(cancel);
    }

    public void setSureButtonEnable(boolean enable){
        btnSure.setEnabled(enable);
    }

    public void setCancelButtonEnable(boolean enable){
        btnCancel.setEnabled(enable);
    }

    private void initListener() {
        btnCancel.setOnClickListener(this);
        btnSure.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v == btnSure) {
            dialogClickListener.dialogSure(order,url);
            dismiss();
        } else if (v == btnCancel) {
            dialogClickListener.dialogCancel();
            dismiss();
        }
    }

    public interface DialogClickListener {
        void dialogSure(int order, String url);

        void dialogCancel();
    }

    public void setDialogClickListener(DialogClickListener dialogClickListener) {
        this.dialogClickListener = dialogClickListener;
    }

}
